<?php 
include_once dirname(__FILE__)."/db.class.php" ;
 class coconcepteur{
		 protected $_result;
		 protected $_cnn;
		 protected $_nom;
		 protected $_prenom;
		 protected $_email;
		 protected $_tel;
		 protected $_id_ue;
		 protected $_grade;
		 protected $_specialite;
		 protected $_id_coconcepteur;
		
		 public function get_name_table(){ return "coconcepteur";}
		 
		 
		 
		 public function get_name_id_coconcepteur(){ return "id_coconcepteur";}
		
		 public function get_name_nom(){ return "nom";}
		 public function get_name_prenom(){ return "prenom";}
		 
		  public function get_name_id_ue(){ return "id_ue";}
		 
		 public function get_name_email(){ return "email";}
		 
		 public function get_name_tel(){ return "tel";}
		
		 public function get_name_grade(){ return "grade";}
		 public function get_name_specialite(){ return "specialite";}
		
		 public function set_id_ue($parametre){  $this->_id_ue=$parametre;}	
		 public function set_id_coconcepteur($parametre){  $this->_id_coconcepteur=$parametre;}	
		 
		 
		 
		 
		 public function set_nom($parametre){  $this->_nom=$parametre;}	
		 public function set_prenom($parametre){  $this->_prenom=$parametre;}	
		
		 public function set_email($parametre){  $this->_email=$parametre;}	
		
		 public function set_tel($parametre){  $this->_tel=$parametre;}	
		
		 public function set_grade($parametre){  $this->_grade=$parametre;}	
		 public function set_specialite($parametre){  $this->_specialite=$parametre;}	
		
		 public function get_id_ue(){ return $this->_id_ue;}
		 
		 
		 public function get_id_coconcepteur(){ return $this->_id_coconcepteur;}
		 
		 
		 
		 public function get_nom(){ return $this->_nom;}
		 public function get_prenom(){ return $this->_prenom;}
		
		 public function get_email(){ return $this->_email;}
	
		 public function get_tel(){ return $this->_tel;}
		
		 public function get_grade(){ return $this->_grade;}
		 public function get_specialite(){ return $this->_specialite;}
		
public function __construct(){
			
		 	$this->_cnn=new Db();

		 }

 public function INSERT()
{

$sql=" INSERT INTO 
 coconcepteur(
			nom,
			prenom,
			email,
			tel,
			grade,
			specialite,
            id_ue,
			id_coconcepteur
			)
 VALUES(
			
			'".$this->_nom."',
			'".$this->_prenom."',
			'".$this->_email."',
			'".$this->_tel."',
			'".$this->_grade."',
            '".$this->_specialite."',
			'".$this->_id_ue."',
			'".$this->_id_coconcepteur."'
			)";
$this->_cnn->connect();
$this->_result=$this->_cnn->query($sql);
$this->_cnn->disconnect();
 if(!$this->_result){return false;}else{return true;}
}

 public function UPDATE()
{

 $sql="";

if(!empty($this->_nom)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
nom='".$this->_nom."'";
}
if(!empty($this->_prenom)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
prenom='".$this->_prenom."'";
}

if(!empty($this->_email)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
email='".$this->_email."'";
}

if(!empty($this->_tel)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
tel='".$this->_tel."'";
}

if(!empty($this->_grade)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
grade='".$this->_grade."'";
}
if(!empty($this->_specialite)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
specialite='".$this->_specialite."'";
}

if(!empty($this->_id_ue)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
id_ue='".$this->_id_ue."'";
}

if(!empty($this->_id_coconcepteur)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
id_coconcepteur='".$this->_id_coconcepteur."'";
}



$sql="
	UPDATE 
		 coconcepteur SET 
 			".$sql."
	WHERE 
		 id_coconcepteur ='".$this->_id_coconcepteur."'
			
	";


$this->_cnn->connect();
$this->_result=$this->_cnn->query($sql);
 $this->_cnn->disconnect();
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function DELETE(){

 $sql="
 		DELETE FROM 
			coconcepteur 
 		WHERE 
			id_coconcepteur = '".$this->_id_coconcepteur."'
		
	";
$this->_cnn->connect();
$this->_result=$this->_cnn->query($sql);
$this->_cnn->disconnect();
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function TRANCATE(){

 $sql="DELETE FROM 
coconcepteur ";
$this->_cnn->connect();
$this->_result=$this->_cnn->query($sql);
$this->_cnn->disconnect();
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function SELECT($constraint="",$pagination="")
{

$sql=" SELECT 
		nom,
		prenom,
		email,
		tel,
		libelle as grade,
		specialite,
		id_ue,
		id_coconcepteur
		
 FROM 
 	coconcepteur
	LEFT JOIN grade ON grade.code_grade=coconcepteur.grade
 ";
if($constraint){$sql.=" WHERE 1=1 ".$constraint;}if($pagination){$sql.=$pagination;}
//echo $sql;
$this->_cnn->connect();
$this->_result=$this->_cnn->query($sql);
$this->_cnn->disconnect();
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

public function fetch_object(){
$row=mysql_fetch_object($this->_result);
 if($this->_result){
 if($row){
		$this->_nom=$row->nom;
		$this->_prenom=$row->prenom;
		$this->_email=$row->email;
		$this->_tel=$row->tel;
		$this->_grade=$row->grade;
		$this->_specialite=$row->specialite;
		$this->_id_ue=$row->id_ue;
		$this->_id_coconcepteur=$row->id_coconcepteur;
		
		return $row;
		}else{
					return false;
				}

			}else{
				//echo 'Erreur d\'execution de requette de selection';	
			}
			

		}

}
?>